home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
edsspell
/
unit1.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
4KB
|
185 lines
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, DBFilter, Grids, DBGrids, DB, DBTables,DBiTypes,DBiProcs,
ExtCtrls, DBCtrls, Mask, TabNotBk;
type
TDemo1 = class(TForm)
Table1: TTable;
DataSource1: TDataSource;
FilterFunc1: TFilterFunc;
Filter: TFilter;
Filter1: TFilter;
TabbedNotebook1: TTabbedNotebook;
StoredBtn: TButton;
Button1: TButton;
DesignerBtn: TButton;
CBackOnBtn: TButton;
CBackOffBtn: TButton;
AddBtn: TButton;
ClearBtn: TButton;
ActivateBtn: TButton;
DeActivateBtn: TButton;
RemoveBtn: TButton;
Label10: TLabel;
Label3: TLabel;
Panel1: TPanel;
DBNavigator1: TDBNavigator;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBGrid1: TDBGrid;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Button2: TButton;
Memo4: TMemo;
Memo5: TMemo;
Table2: TTable;
Button3: TButton;
procedure AddBtnClick(Sender: TObject);
procedure RemoveBtnClick(Sender: TObject);
procedure DeActivateBtnClick(Sender: TObject);
procedure ActivateBtnClick(Sender: TObject);
procedure DesignerBtnClick(Sender: TObject);
procedure ClearBtnClick(Sender: TObject);
procedure StoredBtnClick(Sender: TObject);
procedure CBackOnBtnClick(Sender: TObject);
function FilterFunc1FilterRecord(Sender: TObject;
DataSet: TDataset): Boolean;
procedure CBackOffBtnClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Demo1: TDemo1;
implementation
uses filtfrm;
{$R *.DFM}
procedure TDemo1.AddBtnClick(Sender: TObject);
begin
with Filter do
begin
Dataset:=Table1;
Add('COMPANY',canEQ,'U..',canOR);
Add('LASTINVOICEDATE',canGT,'11/8/94 1:05:03 AM',canNOTDEFINED);
Active:=True;
end;
end;
procedure TDemo1.RemoveBtnClick(Sender: TObject);
begin
Filter.RemoveFilter;
end;
procedure TDemo1.DeActivateBtnClick(Sender: TObject);
begin
Filter.Active:=False;
end;
procedure TDemo1.ActivateBtnClick(Sender: TObject);
begin
Filter.Active:=True;
end;
procedure TDemo1.ClearBtnClick(Sender: TObject);
begin
with Filter do
begin
ClearFilterConditions;
RemoveFilter;
end;
end;
{FilterDesigner demo buttons}
procedure TDemo1.DesignerBtnClick(Sender: TObject);
begin
Filter1.Dataset:=Table1;
with filtfrm.TFilterForm.Create(Application) do
begin
try
Filter:=Filter1;
showmodal;
finally
free;
end;
end;
Filter1.SaveToFile('filter.txt');
end;
procedure TDemo1.Button3Click(Sender: TObject);
begin
Filter1.LoadFromFile('filter.txt');
end;
procedure TDemo1.StoredBtnClick(Sender: TObject);
begin
Filter1.Prepare;
end;
procedure TDemo1.Button1Click(Sender: TObject);
begin
Filter1.Active:=True;
end;
procedure TDemo1.Button2Click(Sender: TObject);
begin
Filter1.RemoveFilter;
end;
{User defined OnFilterRecord Event Handler - the 'Result' variable
determines wether the record is displayed, True it is dsiplayed, False it
is not displayed, you can use you can access any field or object or
other Dataset EXCEPT you mus not do anything that would result in
either a change in the Dataset State or in the Dataset record position!!!!}
function TDemo1.FilterFunc1FilterRecord(Sender: TObject; DataSet: TDataset): Boolean;
var
P:string;
S:integer;
D:longint;
pt:pointer;
t:ttable;
begin
P:=Dataset.fieldbyname('COMPANY').asstring;
S:=pos('c',P);
if S>0 then Result:=True else result:=False;
t:=table2;
D:=Table2.FieldByName('EmpNo').AsInteger;
T.FindKey([D]);
end;
{Turns your filter function on, note if you do not have GoFirst set
then we do not seek for a record to match your criteria we wait for
you to do something that causes a record to be read}
procedure TDemo1.CBackOnBtnClick(Sender: TObject);
begin
FilterFunc1.Active:=True;
end;
{Turns your FilterFunction off,note if you do not have GoFirst set
then we do not refresh the display we wait for you to do something
that causes a record to be read, this can be useful if you use the filter
to seek to a record then turn of and read all records.}
procedure TDemo1.CBackOffBtnClick(Sender: TObject);
begin
FilterFunc1.Active:=False;
end;
end.